package com.hq.fxh.CustomerView.PopupWindow;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.hq.fxh.No3_TuiGuang.MyMoBan.Adapter.MySpringAdapter;
import com.hq.fxh.R;
import com.hq.fxh.Utils.LogUtils;
import com.hq.fxh.Utils.Tool;


/**
 * Created by Administrator on 2017/2/16.
 */
public class PopupForModeShowTime extends PopupWindow   {


    protected View rootView;

    protected ListView popList;
    protected LinearLayout popupPingBi;
    private Activity context;
    private View popView;
    ShareModleCallBack modleCallBack;
    String[] data;


    public PopupForModeShowTime(Activity context, String[] data, ShareModleCallBack modleCallBack) {
        super(context);
        this.context = context;
        this.data=data;
        this.modleCallBack = modleCallBack;
        popView = LayoutInflater.from(context).inflate(R.layout.popup_list, null);
        initView(popView);
        initData();

    }



    public void initData() {

        //设置PopupWindow的View
        this.setContentView(popView);
        //设置PopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置PopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        //设置PopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setAnimationStyle(R.style.dialog_anim_style);
        this.setOutsideTouchable(false);
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
        this.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xffffffff);
    /*    openKeyboard();*/

        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        this.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss() {
                Tool.setAlpha(context, 1f);

            }
        });

    }


    private void initView(View rootView) {

        popList = (ListView) rootView.findViewById(R.id.pop_list);
        popupPingBi = (LinearLayout) rootView.findViewById(R.id.popup_PingBi);
        MySpringAdapter adapter = new MySpringAdapter();
         adapter.setData(data);
        popList.setAdapter(adapter);

        popList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                String data = adapterView.getItemAtPosition(i).toString();
                 LogUtils.e(data);
                modleCallBack.callSure(i,data);
            }
        });



    }


    public void show(View view) {

        showAtLocation(view, Gravity.BOTTOM, 0, 0);
        Tool.setAlpha(context, 0.7f);
    }




    public interface ShareModleCallBack {
       public void callSure(int position,String comment);

    }


}
